let express = require('express');
let path = require('path');

let config = require('./config/config.js');

let app = express();


// 解析application/json类型的数据
app.use(express.json());
// 解析application/x-www-form-urlencoded类型的数据
app.use(express.urlencoded({extended: true}));

let {responseMiddleware} = require('./util/responseMiddleware.js');
app.use(responseMiddleware);

// ------------- 项目路由设置 开始 -------------
let indexRouter = require('./routes/index');
app.use('/', indexRouter);
// ------------- 项目路由设置 结束 -------------


app.use(express.static(path.join(__dirname, 'public')));

app.all('*', function (req, res, next) {
    res.error("接口不存在", 404)
});

app.listen(config.port, () => {
    console.log('express server running at http://127.0.0.1:' + config.port)
})